/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package amd.core.calculation;

import Jama.Matrix;

/**
 *
 * @author Latifah Dwi Nurachma
 */
class Vector {

    public static float[] getRowVector(Matrix matrix, int iRow) {
        float[] rowVector = new float[matrix.getColumnDimension()];
        int i=0, nCol = matrix.getColumnDimension();
        while(i< nCol){
            rowVector[i] = (float) matrix.get(iRow, i);
            i++;
        }
        return rowVector;
    }

    public static float[] getColVector(Matrix matrix, int iCol){
        float[] colVector = new float[matrix.getRowDimension()];
        int i=0, nRow = matrix.getRowDimension();
        while(i< nRow){
            colVector[i] = (float) matrix.get(i, iCol);
            i++;
        }
        return colVector;
    }

    public static float innerProduct(float[] vectorA, float[] vectorB) {
        float product=0;
        int nA = vectorA.length;
        int nB = vectorB.length;
        if(nA == nB){
            int i=0;
            while(i<nA){
                product = product + vectorA[i]*vectorB[i];
                i++;
            }
        }
        return product;
    }

    public static float lengthVector(float[] vector) {
        float length=0;
        int i=0;
        float sumSquare=0;
        while (i<vector.length){
            sumSquare = sumSquare + (vector[i] * vector[i]);
            i++;
        }
        length = (float) Math.sqrt(sumSquare);
        return length;
    }

}
